package com.homer.android.sdk.action.device.common;

import java.net.InetAddress;

import com.homer.android.sdk.command.uart.EspCommandUartPostStatusLocal;
import com.homer.android.sdk.command.uart.IEspCommandUartPostStatusLocal;
import com.homer.android.sdk.devcie.IEspDevice;
import com.homer.android.sdk.devcie.IEspDeviceSSS;
import com.homer.android.sdk.devcie.IEspDeviceUart;
import com.homer.android.sdk.devcie.status.IEspStatusUart;
import com.homer.iot.esptouch.udp.EspDeviceType;

public class EspActionDevicePostStatusLocal implements
		IEspActionDevicePostStatusLocal {
	private boolean __doActionDevicePostStatusLocal(IEspDevice device,
			String base64Param) {
		EspDeviceType deviceType = device.getDeviceType();
		InetAddress inetAddress = device.getInetAddress();
		String deviceBssid = device.getBssid();
		boolean suc = false;
		switch (deviceType) {
		case UART:
			IEspCommandUartPostStatusLocal uartCommand = new EspCommandUartPostStatusLocal();
			suc = uartCommand.doCommandUartPostStatusLocal(inetAddress,
					base64Param, deviceBssid);
			if (suc) {
				IEspStatusUart statusUart;
				if (device instanceof IEspDeviceSSS) {
					statusUart = (IEspStatusUart) ((IEspDeviceSSS) device)
							.getDeviceStatus();
				} else {

					statusUart = ((IEspDeviceUart) device).getStatusUart();
				}

				statusUart.setIsOnline(true);
			}
			return suc;
		case NEW:
			break;
		default:
			break;
		}
		throw new IllegalArgumentException();
	}

	@Override
	public boolean doActionDevicePostStatusLocal(IEspDevice device,
			String base64Param) {
		return __doActionDevicePostStatusLocal(device, base64Param);
	}

	// private void doRootRouterCommandLocal(IEspDeviceRoot device,
	// IEspDeviceStatus status)
	// {
	// List<IEspDeviceTreeElement> childList =
	// device.getDeviceTreeElementList();
	// for (IEspDeviceTreeElement element : childList)
	// {
	// if (element.getLevel() == FIRST_CHILD_LEVEL)
	// {
	// IEspDevice child = element.getCurrentDevice();
	// EspBaseApiUtil.submit(new RootStatusRunnable(child, status));
	// }
	// }
	// }
	//
	// private class RootStatusRunnable implements Runnable
	// {
	// private IEspDevice device;
	//
	// private IEspDeviceStatus status;
	//
	// public RootStatusRunnable(IEspDevice device, IEspDeviceStatus status)
	// {
	// this.device = device;
	// this.status = status;
	// }
	//
	// @Override
	// public void run()
	// {
	// InetAddress inetAddress = device.getInetAddress();
	// String bssid = device.getBssid();
	//
	//
	// if (status instanceof IEspStatusUart)
	// {
	// IEspStatusUart uartStatus = (IEspStatusUart)status;
	// IEspCommandUartPostStatusLocal uartCommand = new
	// EspCommandUartPostStatusLocal();
	// uartCommand.doCommandUartPostStatusLocal(inetAddress, uartStatus, bssid);
	// }
	// }
	//
	// }
}
